当前位置: 首页>>代码示例>>C++>>正文


C++ CBGetMessage函数代码示例

本文整理汇总了C++中CBGetMessage函数的典型用法代码示例。如果您正苦于以下问题:C++ CBGetMessage函数的具体用法?C++ CBGetMessage怎么用?C++ CBGetMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了CBGetMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CBTransactionOutputCalculateLength

uint32_t CBTransactionOutputCalculateLength(CBTransactionOutput * self){
	if (CBGetMessage(self)->serialised) {
		// If it is serailised, the var int may be of a different size.
		uint8_t byte = CBByteArrayGetByte(CBGetMessage(self)->bytes, 0);
		return (byte < 253 ? 1 : (byte == 253 ? 3 : (byte == 254 ? 5 : 9))) + self->scriptObject->length + 8;
	} else return CBVarIntSizeOf(self->scriptObject->length) + self->scriptObject->length + 8;
}
开发者ID:GMD1987,项目名称:cbitcoin,代码行数:7,代码来源:CBTransactionOutput.c

示例2: CBNetworkAddressSerialise

uint8_t CBNetworkAddressSerialise(CBNetworkAddress * self, bool timestamp){
	CBByteArray * bytes = CBGetMessage(self)->bytes;
	if (! bytes) {
		CBLogError("Attempting to serialise a CBNetworkAddress with no bytes.");
		return 0;
	}
	if (bytes->length < 26 + timestamp * 4) {
		CBLogError("Attempting to serialise a CBNetworkAddress with less bytes than required.");
		return 0;
	}
	uint8_t cursor;
	if (timestamp) {
		CBByteArraySetInt32(bytes, 0, (uint32_t)(self->lastSeen - self->penalty));
		cursor = 4;
	}else cursor = 0;
	CBByteArraySetInt64(bytes, cursor, self->services);
	cursor += 8;
	CBByteArrayCopyByteArray(bytes, cursor, self->ip);
	CBByteArrayChangeReference(self->ip, bytes, cursor);
	cursor += 16;
	CBByteArraySetPort(bytes, cursor, self->port);
	bytes->length = cursor + 2;
	CBGetMessage(self)->serialised = true;
	return cursor + 2;
}
开发者ID:Jud,项目名称:cbitcoin,代码行数:25,代码来源:CBNetworkAddress.c

示例3: CBAlertSerialiseSignature

int CBAlertSerialiseSignature(CBAlert * self, int offset) {
	
	CBByteArray * bytes = CBGetMessage(self)->bytes;
	if (! bytes) {
		CBLogError("Attempting to serialise a CBAlert with no bytes.");
		return 0;
	}
	
	CBVarInt sigLen = CBVarIntFromUInt64(self->signature->length);
	if (bytes->length < offset + sigLen.size + sigLen.val) {
		CBLogError("Attempting to serialise a CBAlert with less bytes than required for the signature.");
		return 0;
	}
	
	CBByteArraySetVarInt(bytes, offset, sigLen);
	offset += sigLen.size;
	
	CBByteArrayCopyByteArray(bytes, offset, self->signature);
	CBByteArrayChangeReference(self->signature, bytes, offset);
	
	bytes->length = offset + (int)sigLen.val;
	
	CBGetMessage(self)->serialised = true;
	
	return bytes->length;
	
}
开发者ID:01BTC10,项目名称:cbitcoin,代码行数:27,代码来源:CBAlert.c

示例4: CBTransactionOutputSerialise

uint32_t CBTransactionOutputSerialise(CBTransactionOutput * self){
	CBByteArray * bytes = CBGetMessage(self)->bytes;
	if (NOT bytes) {
		CBLogError("Attempting to serialise a CBTransactionInput with no bytes.");
		return 0;
	}
	if (NOT self->scriptObject){
		CBLogError("Attempting to serialise a CBTransactionOutput without scriptObject.");
		return 0;
	}
	CBVarInt scriptLen = CBVarIntFromUInt64(CBGetByteArray(self->scriptObject)->length);
	uint32_t reqLen = 8 + scriptLen.size + CBGetByteArray(self->scriptObject)->length;
	if (bytes->length < reqLen) {
		CBLogError("Attempting to serialise a CBTransactionOutput with less bytes than required. %i < %i", bytes->length, reqLen);
		return 0;
	}
	// Serialise data into the CBByteArray and rereference objects to this CBByteArray to save memory.
	CBByteArraySetInt64(bytes, 0, self->value);
	CBVarIntEncode(bytes, 8, scriptLen);
	CBByteArrayCopyByteArray(bytes, 8 + scriptLen.size, CBGetByteArray(self->scriptObject));
	CBByteArrayChangeReference(CBGetByteArray(self->scriptObject), bytes, 8 + scriptLen.size);
	// Ensure length is correct
	bytes->length = reqLen;
	// Is serialised.
	CBGetMessage(self)->serialised = true;
	return reqLen;
}
开发者ID:GMD1987,项目名称:cbitcoin,代码行数:27,代码来源:CBTransactionOutput.c

示例5: CBAddressBroadcastDeserialise

uint32_t CBAddressBroadcastDeserialise(CBAddressBroadcast * self){
	CBByteArray * bytes = CBGetMessage(self)->bytes;
	if (NOT bytes) {
		CBGetMessage(self)->onErrorReceived(CB_ERROR_MESSAGE_DESERIALISATION_NULL_BYTES,"Attempting to deserialise a CBAddressBroadcast with no bytes.");
		return 0;
	}
	if (bytes->length < 26 + self->timeStamps * 4) {
		CBGetMessage(self)->onErrorReceived(CB_ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialise a CBAddressBroadcast without enough bytes to cover one address.");
		return 0;
	}
	CBVarInt num = CBVarIntDecode(bytes, 0);
	if (num.val > 30) {
		CBGetMessage(self)->onErrorReceived(CB_ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"Attempting to deserialise a CBAddressBroadcast with a var int over 30.");
		return 0;
	}
	self->addresses = malloc(sizeof(*self->addresses) * (size_t)num.val);
	if (NOT self->addresses) {
		CBGetMessage(self)->onErrorReceived(CB_ERROR_OUT_OF_MEMORY,"Cannot allocate %i bytes of memory in CBAddressBroadcastDeserialise\n",sizeof(*self->addresses) * (size_t)num.val);
		return 0;
	}
	self->addrNum = num.val;
	uint16_t cursor = num.size;
	for (uint8_t x = 0; x < num.val; x++) {
		// Make new CBNetworkAddress from the rest of the data.
		uint8_t len;
		CBByteArray * data = CBByteArraySubReference(bytes, cursor, bytes->length-cursor);
		if (data) {
			self->addresses[x] = CBNewNetworkAddressFromData(data, CBGetMessage(self)->onErrorReceived);
			if (self->addresses[x]){
				// Deserialise
				len = CBNetworkAddressDeserialise(self->addresses[x], self->timeStamps);
				if (NOT len)
					CBGetMessage(self)->onErrorReceived(CB_ERROR_MESSAGE_DESERIALISATION_BAD_BYTES,"CBAddressBroadcast cannot be deserialised because of an error with the CBNetworkAddress number %u.",x);
			}else{
				len = 0;
				CBGetMessage(self)->onErrorReceived(CB_ERROR_INIT_FAIL,"Could not create CBNetworkAddress in CBAddressBroadcastDeserialise for network address %u.",x);
			}
		}else{
			len = 0;
			CBGetMessage(self)->onErrorReceived(CB_ERROR_INIT_FAIL,"Could not create CBByteArray in CBAddressBroadcastDeserialise for network address %u.",x);
		}
		if (NOT len) {
			// Release bytes
			CBReleaseObject(data);
			return 0;
		}
		// Adjust length
		data->length = len;
		CBReleaseObject(data);
		cursor += len;
	}
	return cursor;
}
开发者ID:dirschneid,项目名称:cbitcoin,代码行数:53,代码来源:CBAddressBroadcast.c

示例6: CBInitNetworkAddressFromData

bool CBInitNetworkAddressFromData(CBNetworkAddress * self, CBByteArray * data, bool isPublic){
	self->ip = NULL;
	self->bucketSet = false;
	if (NOT CBInitMessageByData(CBGetMessage(self), data))
		return false;
	return true;
}
开发者ID:GMD1987,项目名称:cbitcoin,代码行数:7,代码来源:CBNetworkAddress.c

示例7: CBInitNetworkAddress

bool CBInitNetworkAddress(CBNetworkAddress * self, uint64_t lastSeen, CBByteArray * ip, uint16_t port, CBVersionServices services, bool isPublic){
	self->lastSeen = lastSeen;
	self->penalty = 0;
	self->ip = ip;
	self->isPublic = isPublic;
	if (NOT ip) {
		ip = CBNewByteArrayOfSize(16);
		if (NOT ip)
			return false;
		memset(CBByteArrayGetData(ip), 0, 16);
		self->type = CB_IP_INVALID;
	}else{
		// Determine IP type
		self->type = CBGetIPType(CBByteArrayGetData(ip));
		CBRetainObject(ip);
	}
	self->port = port;
	self->services = services;
	self->bucketSet = false;
	if (NOT CBInitMessageByObject(CBGetMessage(self))){
		CBReleaseObject(ip);
		return false;
	}
	return true;
}
开发者ID:GMD1987,项目名称:cbitcoin,代码行数:25,代码来源:CBNetworkAddress.c

示例8: CBInitInventoryBroadcastFromData

bool CBInitInventoryBroadcastFromData(CBInventoryBroadcast * self,CBByteArray * data,CBEvents * events){
	self->itemNum = 0;
	self->items = NULL;
	if (NOT CBInitMessageByData(CBGetMessage(self), data, events))
		return false;
	return true;
}
开发者ID:a5an0,项目名称:cbitcoin,代码行数:7,代码来源:CBInventoryBroadcast.c

示例9: CBInitInventoryFromData

void CBInitInventoryFromData(CBInventory * self, CBByteArray * data) {
	
	self->itemNum = 0;
	self->itemFront = NULL;
	CBInitMessageByData(CBGetMessage(self), data);
	
}
开发者ID:KBryan,项目名称:cbitcoin,代码行数:7,代码来源:CBInventory.c

示例10: CBInitBlockHeadersFromData

bool CBInitBlockHeadersFromData(CBBlockHeaders * self,CBByteArray * data,void (*logError)(char *,...)) {
    self->headerNum = 0;
    self->blockHeaders = NULL;
    if (NOT CBInitMessageByData(CBGetMessage(self), data, logError))
        return false;
    return true;
}
开发者ID:applsdev,项目名称:cbitcoin,代码行数:7,代码来源:CBBlockHeaders.c

示例11: CBTransactionInputDeserialise

uint32_t CBTransactionInputDeserialise(CBTransactionInput * self){
	CBByteArray * bytes = CBGetMessage(self)->bytes;
	if (! bytes) {
		CBLogError("Attempting to deserialise a CBTransactionInput with no bytes.");
		return 0;
	}
	if (bytes->length < 41) {
		CBLogError("Attempting to deserialise a CBTransactionInput with less than 41 bytes.");
		return 0;
	}
	CBVarInt scriptLen = CBVarIntDecode(bytes, 36);
	if (scriptLen.val > 10000) {
		CBLogError("Attempting to deserialise a CBTransactionInput with too big a script.");
		return 0;
	}
	uint32_t reqLen = (uint32_t)(40 + scriptLen.size + scriptLen.val);
	if (bytes->length < reqLen) {
		CBLogError("Attempting to deserialise a CBTransactionInput with less bytes than needed according to the length for the script. %i < %i", bytes->length, reqLen);
		return 0;
	}
	// Deserialise by subreferencing byte arrays and reading integers.
	self->prevOut.hash = CBByteArraySubReference(bytes, 0, 32);
	self->prevOut.index = CBByteArrayReadInt32(bytes, 32);
	self->scriptObject = CBNewScriptFromReference(bytes, 36 + scriptLen.size, (uint32_t) scriptLen.val);
	self->sequence = CBByteArrayReadInt32(bytes, (uint32_t) (36 + scriptLen.size + scriptLen.val));
	return reqLen;
}
开发者ID:Jud,项目名称:cbitcoin,代码行数:27,代码来源:CBTransactionInput.c

示例12: CBInitBlockHeaders

bool CBInitBlockHeaders(CBBlockHeaders * self) {
    self->headerNum = 0;
    self->blockHeaders = NULL;
    if (NOT CBInitMessageByObject(CBGetMessage(self)))
        return false;
    return true;
}
开发者ID:austonst,项目名称:cbitcoin,代码行数:7,代码来源:CBBlockHeaders.c

示例13: CBInitChainDescriptorFromData

bool CBInitChainDescriptorFromData(CBChainDescriptor * self,CBByteArray * data,void (*logError)(char *,...)){
	self->hashNum = 0;
	self->hashes = NULL;
	if (NOT CBInitMessageByData(CBGetMessage(self), data, logError))
		return false;
	return true;
}
开发者ID:applsdev,项目名称:cbitcoin,代码行数:7,代码来源:CBChainDescriptor.c

示例14: CBInitChainDescriptor

bool CBInitChainDescriptor(CBChainDescriptor * self,void (*logError)(char *,...)){
	self->hashNum = 0;
	self->hashes = NULL;
	if (NOT CBInitMessageByObject(CBGetMessage(self), logError))
		return false;
	return true;
}
开发者ID:applsdev,项目名称:cbitcoin,代码行数:7,代码来源:CBChainDescriptor.c

示例15: CBInitTransactionInputFromData

bool CBInitTransactionInputFromData(CBTransactionInput * self, CBByteArray * data,void (*onErrorReceived)(CBError error,char *,...)){
	self->scriptObject = NULL;
	self->prevOut.hash = NULL;
	if (NOT CBInitMessageByData(CBGetMessage(self), data, onErrorReceived))
		return false;
	return true;
}
开发者ID:dirschneid,项目名称:cbitcoin,代码行数:7,代码来源:CBTransactionInput.c


注:本文中的CBGetMessage函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。