Dart DocumentationbsonBsonString

BsonString class

class BsonString extends BsonObject{
 String data;
 List<int> _utfData;
 List<int> get utfData{
   if (_utfData == null){
     _utfData = UTF8.encode(data);
   }
   return _utfData;
 }
 BsonString(this.data);
 get value=>data;
 byteLength()=>utfData.length+1+4;
 int get typeByte => _BSON_DATA_STRING;
 packValue(BsonBinary buffer){
    buffer.writeInt(utfData.length+1);
    buffer.byteList.setRange(buffer.offset,buffer.offset+utfData.length,utfData);
    buffer.offset += utfData.length;
    buffer.writeByte(0);
 }
 unpackValue(BsonBinary buffer){
    int size = buffer.readInt32()-1;
    data = UTF8.decode(buffer.byteList.getRange(buffer.offset, buffer.offset+size).toList());
    buffer.offset += size+1;
 }
}

Extends

BsonObject > BsonString

Subclasses

BsonCString, BsonCode

Constructors

new BsonString(String data) #

Creates a new Object instance.

Object instances have no meaningful state, and are only useful through their identity. An Object instance is equal to itself only.

docs inherited from Object
BsonString(this.data);

Properties

String data #

String data

final int typeByte #

int get typeByte => _BSON_DATA_STRING;

final List<int> utfData #

List<int> get utfData{
 if (_utfData == null){
   _utfData = UTF8.encode(data);
 }
 return _utfData;
}

final value #

get value=>data;

Methods

dynamic byteLength() #

byteLength()=>utfData.length+1+4;

dynamic packElement(String name, buffer) #

inherited from BsonObject
packElement(String name, var buffer){
 buffer.writeByte(typeByte);
 if (name != null){
   new BsonCString(name).packValue(buffer);
 }
 packValue(buffer);
}

dynamic packValue(BsonBinary buffer) #

packValue(BsonBinary buffer){
  buffer.writeInt(utfData.length+1);
  buffer.byteList.setRange(buffer.offset,buffer.offset+utfData.length,utfData);
  buffer.offset += utfData.length;
  buffer.writeByte(0);
}

_ElementPair unpackElement(buffer) #

inherited from BsonObject
_ElementPair unpackElement(buffer){
 _ElementPair result = new _ElementPair();
 result.name = buffer.readCString();
 unpackValue(buffer);
 result.value = value;
 return result;
}

dynamic unpackValue(BsonBinary buffer) #

unpackValue(BsonBinary buffer){
  int size = buffer.readInt32()-1;
  data = UTF8.decode(buffer.byteList.getRange(buffer.offset, buffer.offset+size).toList());
  buffer.offset += size+1;
}