public static void fix_read(zero_copy_buffer stream, ref UInt32 value) { if (stream.read_len + 4 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } if (IsLittleEndian) { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; } else { stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; } value = stream.value.VU32; }
public static void read(zero_copy_buffer stream, ref Int16 value) { if (stream.read_len + 1 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = (Int16)stream.buffer[stream.read_len++]; if (value >= 0 && value <= const_tag_as_value) { return; } int read_bytes = (value & const_interger_byte_msak) + 1; if (read_bytes > 2) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } if (stream.read_len + read_bytes > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } bool signed = (value & const_negative_bit_value) > 0; stream.value.VU64 = 0; if (IsLittleEndian) { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; break; } } } else { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } } } if (signed) { value = (Int16)(-stream.value.VI16); } else { value = stream.value.VI16; } }
public static void read(zero_copy_buffer stream, ref string value, UInt32 len) { if (stream.read_len + len > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } char[] chars = new char[len]; for (int i = 0; i < len; ++i) { chars[i] = (char)stream.buffer[stream.read_len++]; } value = new string(chars); return; }
public static void fix_write(zero_copy_buffer stream, UInt64 value) { if (stream.write_len + 8 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; } else { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; } }
public static void read(zero_copy_buffer stream, ref sbyte value) { if (stream.read_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = (sbyte)stream.buffer[stream.read_len++]; if (value >= 0 && value <= const_tag_as_value) { return; } int read_bytes = (value & const_interger_byte_msak) + 1; if (read_bytes > 1) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } bool signed = (value & const_negative_bit_value) > 0; if (stream.read_len + read_bytes >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = (sbyte)stream.buffer[stream.read_len++]; if (signed) { value = (sbyte)-value; } }
public static void write(zero_copy_buffer stream, string value, UInt32 len) { if (stream.write_len + len > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } for (int i = 0; i < len; ++i) { stream.buffer[stream.write_len++] = (byte)value[i]; } return; }
public static void fix_skip_read(zero_copy_buffer stream, ref UInt64 value) { if (stream.read_len + 8 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.read_len += 8; }
public static void skip_read(zero_copy_buffer stream, ref UInt64 value) { if (stream.read_len + 1 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } byte tag = stream.buffer[stream.read_len++]; if (tag <= const_tag_as_value) { return; } int read_bytes = (int)(tag & const_interger_byte_msak) + 1; if (read_bytes > 8) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } if (stream.read_len + read_bytes > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.read_len += read_bytes; }
public static void skip_read(zero_copy_buffer stream, ref float value) { if (stream.read_len + 4 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.read_len += 4; }
public static void read(zero_copy_buffer stream, ref string value, UInt32 len) { if (stream.read_len + len > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = stream.m_encoding.GetString(stream.buffer, stream.read_len, (int)len); stream.read_len += (int)len; return; }
public static void read(zero_copy_buffer stream, ref string value) { UInt32 len = 0; read(stream, ref len); read(stream, ref value, len); }
public static void fix_read(zero_copy_buffer stream, ref byte value) { if (stream.read_len + 1 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = stream.buffer[stream.read_len++]; }
public static UInt32 check_read_size(zero_copy_buffer stream, int size) { UInt32 len = 0; read(stream, ref len); if (stream.error()) { return 0; } if (size > 0 && len > size) { stream.error_code = error_code_t.number_of_element_not_macth; return 0; } return len; }
public static UInt32 check_read_size(zero_copy_buffer stream) { return check_read_size(stream, 0); }
public static void write(zero_copy_buffer stream, Int64 value) { if (0 <= value && value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; } else { byte tag = const_tag_as_type; if (value < 0) { tag += const_negative_bit_value; value = -value; } if (value < 0x100) { if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = tag; stream.buffer[stream.write_len++] = (byte)value; } else if (value < 0x10000) { if (stream.write_len + 3 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; ++tag; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; } else { stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x1000000) { if (stream.write_len + 4 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 2; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; } else { stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x100000000) { if (stream.write_len + 5 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 3; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; } else { stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x10000000000) { if (stream.write_len + 6 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 4; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; } else { stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x1000000000000) { if (stream.write_len + 7 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 5; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; } else { stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x100000000000000) { if (stream.write_len + 8 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 6; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte6; } else { stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else { if (stream.write_len + 9 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI64 = value; tag += 7; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte7; } else { stream.buffer[stream.write_len++] = stream.value.Byte7; stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } } }
public static void skip_read(zero_copy_buffer stream, ref string value, UInt32 len) { if (stream.read_len + len > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.read_len += (int)len; return; }
public static void write(zero_copy_buffer stream, UInt64 value) { if (value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; } else { if (value < 0x100) { if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = 0x80; stream.buffer[stream.write_len++] = (byte)value; } else if (value < 0x10000) { if (stream.write_len + 3 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x81; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; } else { stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x1000000) { if (stream.write_len + 4 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x82; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; } else { stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x100000000) { if (stream.write_len + 5 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x83; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; } else { stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x10000000000) { if (stream.write_len + 6 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x84; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; } else { stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x1000000000000) { if (stream.write_len + 7 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x85; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; } else { stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else if (value < 0x100000000000000) { if (stream.write_len + 8 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x86; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte6; } else { stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } else { if (stream.write_len + 9 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = value; stream.buffer[stream.write_len++] = 0x87; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte7; } else { stream.buffer[stream.write_len++] = stream.value.Byte7; stream.buffer[stream.write_len++] = stream.value.Byte6; stream.buffer[stream.write_len++] = stream.value.Byte5; stream.buffer[stream.write_len++] = stream.value.Byte4; stream.buffer[stream.write_len++] = stream.value.Byte3; stream.buffer[stream.write_len++] = stream.value.Byte2; stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } } }
public static void skip_read_compatible(zero_copy_buffer stream) { int offset = stream.read_len; UInt64 tag = 0; read(stream, ref tag); if (stream.error()) { return; } Int32 len_tag = 0; read(stream, ref len_tag); if (stream.error()) { return; } UInt32 read_len = (UInt32)(stream.read_len - offset); UInt32 len = (UInt32)len_tag; if (len > read_len) stream.skip_read(len - read_len); }
public static void write(zero_copy_buffer stream, string value) { UInt32 len = (UInt32)value.Length; write(stream, len); write(stream, value, len); }
public static void write(zero_copy_buffer stream, sbyte value) { if (0 <= value && value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; } else { byte tag = const_tag_as_type; if (value < 0) { tag += const_negative_bit_value; value = (sbyte)(-value); } if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = tag; stream.buffer[stream.write_len++] = (byte)value; } }
public static void fix_write(zero_copy_buffer stream, byte value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; }
public static void write(zero_copy_buffer stream, byte value) { if (value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = value; } else { byte tag = const_tag_as_type; if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = tag; stream.buffer[stream.write_len++] = value; } }
public static void read(zero_copy_buffer stream, ref double value) { if (stream.read_len + 8 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } if (IsLittleEndian) { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte6 = stream.buffer[stream.read_len++]; stream.value.Byte7 = stream.buffer[stream.read_len++]; } else { stream.value.Byte7 = stream.buffer[stream.read_len++]; stream.value.Byte6 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; } value = stream.value.VF64; }
public static void write(zero_copy_buffer stream, Int16 value) { if (0 <= value && value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; } else { byte tag = const_tag_as_type; if (value < 0) { tag += const_negative_bit_value; value = (Int16)(-value); } if (value < 0x100) { if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = tag; stream.buffer[stream.write_len++] = (byte)value; } else { if (stream.write_len + 3 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VI16 = value; ++tag; stream.buffer[stream.write_len++] = tag; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; } else { stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } } }
public static void read(zero_copy_buffer stream, ref byte value) { if (stream.read_len + 1 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = stream.buffer[stream.read_len++]; if (value >= 0 && value <= const_tag_as_value) { return; } int read_bytes = (value & const_interger_byte_msak) + 1; if (read_bytes > 1) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } if (stream.read_len + read_bytes > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = stream.buffer[stream.read_len++]; }
public static void write(zero_copy_buffer stream, UInt16 value) { if (value <= const_tag_as_value) { if (stream.write_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = (byte)value; } else { if (value < 0x100) { if (stream.write_len + 2 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.buffer[stream.write_len++] = 0x80; stream.buffer[stream.write_len++] = (byte)value; } else { if (stream.write_len + 3 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU16 = value; stream.buffer[stream.write_len++] = 0x81; if (IsLittleEndian) { stream.buffer[stream.write_len++] = stream.value.Byte0; stream.buffer[stream.write_len++] = stream.value.Byte1; } else { stream.buffer[stream.write_len++] = stream.value.Byte1; stream.buffer[stream.write_len++] = stream.value.Byte0; } } } }
public static void read(zero_copy_buffer stream, ref UInt32 value) { if (stream.read_len + 1 > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = (UInt32)stream.buffer[stream.read_len++]; if (value >= 0 && value <= const_tag_as_value) { return; } UInt32 read_bytes = (value & const_interger_byte_msak) + 1; if (read_bytes > 4) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } if (stream.read_len + read_bytes > stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = 0; if (IsLittleEndian) { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; break; } case 3: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; break; } case 4: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; break; } } } else { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 3: { stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 4: { stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } } } value = stream.value.VU32; }
public static void read(zero_copy_buffer stream, ref Int64 value) { if (stream.read_len + 1 >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } value = (Int64)stream.buffer[stream.read_len++]; if (value >= 0 && value <= const_tag_as_value) { return; } int read_bytes = (int)(value & const_interger_byte_msak) + 1; if (read_bytes > 8) { stream.error_code = error_code_t.value_too_large_to_integer_number; return; } if (stream.read_len + read_bytes >= stream.data_len) { stream.error_code = error_code_t.stream_buffer_overflow; return; } stream.value.VU64 = 0; bool signed = (value & const_negative_bit_value) > 0; if (IsLittleEndian) { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; break; } case 3: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; break; } case 4: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; break; } case 5: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; break; } case 6: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; break; } case 7: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte6 = stream.buffer[stream.read_len++]; break; } case 8: { stream.value.Byte0 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte6 = stream.buffer[stream.read_len++]; stream.value.Byte7 = stream.buffer[stream.read_len++]; break; } } } else { switch (read_bytes) { case 1: { stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 2: { stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 3: { stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 4: { stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 5: { stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 6: { stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 7: { stream.value.Byte6 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } case 8: { stream.value.Byte7 = stream.buffer[stream.read_len++]; stream.value.Byte6 = stream.buffer[stream.read_len++]; stream.value.Byte5 = stream.buffer[stream.read_len++]; stream.value.Byte4 = stream.buffer[stream.read_len++]; stream.value.Byte3 = stream.buffer[stream.read_len++]; stream.value.Byte2 = stream.buffer[stream.read_len++]; stream.value.Byte1 = stream.buffer[stream.read_len++]; stream.value.Byte0 = stream.buffer[stream.read_len++]; break; } } } if (signed) { value = -stream.value.VI64; } else { value = stream.value.VI64; } }