下面的代码在Windows上使用命令#include <string.h>
void encDec32(char * a, char * b)
{
const int e = 1;
if (*((char *) &e)) {
memcpy(a, b, 4);
}
else {
a[0] = b[3];
a[1] = b[2];
a[2] = b[1];
a[3] = b[0];
}
}
void encDec64(char * a, char * b)
{
const int e = 1;
if (*((char *) &e)) {
memcpy(a, b, 8);
}
else {
a[0] = b[7];
a[1] = b[6];
a[2] = b[5];
a[3] = b[4];
a[4] = b[3];
a[5] = b[2];
a[6] = b[1];
a[7] = b[0];
}
}
void encodeU32(char ** buffer, uint32_t v)
{
encDec32(*buffer, (char *) &v);
*buffer += 4;
}
void encodeU64(char ** buffer, uint64_t v)
{
encDec64(*buffer, (char *) &v);
*buffer += 8;
}
void encodeFloat(char ** buffer, float v)
{
encDec32(*buffer, (char *) &v);
*buffer += 4;
}
void encodeDouble(char ** buffer, double v)
{
encDec64(*buffer, (char *) &v);
*buffer += 8;
}
void encodeUlong(char ** buffer, unsigned long v)
{
/* force on 8 bytes to be compatible with CPU 32 and 64 */
encodeU64(buffer, (uint64_t) v);
}
uint32_t decodeU32(char ** buffer)
{
uint32_t v;
encDec32((char *) &v, *buffer);
*buffer += 4;
return v;
}
uint64_t decodeU64(char ** buffer)
{
uint64_t v;
encDec64((char *) &v, *buffer);
*buffer += 8;
return v;
}
float decodeFloat(char ** buffer)
{
float v;
encDec32((char *) &v, *buffer);
*buffer += 4;
return v;
}
float decodeDouble(char ** buffer)
{
double v;
encDec64((char *) &v, *buffer);
*buffer += 8;
return v;
}
unsigned long decodeUlong(char ** buffer)
{
/* force on 8 bytes to be compatible with CPU 32 and 64 */
return (unsigned long) decodeU64(buffer);
}
/* for a struct */
typedef struct S {
unsigned long u; /* may be on 32 or 64 and not the same size on Linuw and Windows */
double d1;
double d2;
} S;
/* b is the block to send, it must be enough long */
/* return the number of bytes to send in a block through UDP */
size_t encodeS(char * b, S * s)
{
char * b0 = b;
encodeUlong(&b, s->u);
encodeDouble(&b, s->d1);
encodeDouble(&b, s->d2);
return b - b0;
}
/* b is the block read through UDP */
void decodeS(char * b, S * s)
{
s->u = decodeUlong(&b);
s->d1 = decodeDouble(&b);
s->d2 = decodeDouble(&b);
}
可以正常工作。
mpm i
已打开Windows的凭据格式标准,并已通过登录名和密码。
但是在Linux上会返回认证错误。
"dependencies": {
"my-pack": "git+https://myprivategit.com/my/repo#v0.1.0"
},
答案 0 :(得分:1)
好像您需要添加凭据,您可以尝试以下操作吗:
npm install
从中的存储库生成访问令牌。例如,转到here创建访问令牌。在您的package.json
中前缀您的GIT存储库,以使用从步骤1生成的访问令牌:
"dependencies": {
"my-pack": "git+https://<token>:x-oauth-basic@github.com/<user>/myprivategit.com/my/repo#v0.1.0"
},
或:
在您的主目录中创建一个.netrc
,并为其提供登录所需的凭据:
touch ~/.netrc
.netrc:
machine github.com login <token>
然后将网址保留在.package.json
答案 1 :(得分:0)
对我有用的是将npm与存储在.ssh中的ssh密钥一起安装。
npm install git+ssh://git@your_git_server.com:your_username/your_private_repo_name.git
我遵循了这个tutorial。